//
//  LoginViewController.m
//  TTFriend
//
//  Created by 李正兵 on 2019/5/6.
//  Copyright © 2019 李正兵. All rights reserved.
//

#import "LoginViewController.h"
#import "YYSimpleWebViewController.h"
#import "LoginManager.h"

@interface LoginViewController ()
@property (weak, nonatomic) IBOutlet UITextField *userTextField;
@property (weak, nonatomic) IBOutlet UITextField *passwordTextField;

@end

@implementation LoginViewController

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    self.navigationController.navigationBar.hidden = YES;
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    self.navigationController.navigationBar.hidden = NO;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
}
- (IBAction)login:(id)sender {
    if (_userTextField.text.length == 0) {
        [self showAlertText:@"请输入用户名"];
    }
    
    if (_userTextField.text.length == 0) {
        [self showAlertText:@"请输入密码"];
    }
    
    [[LoginManager shareManager] login:_userTextField.text password:_passwordTextField.text completion:^(BOOL succuss) {
        if (succuss) {
            [self dismissViewControllerAnimated:YES completion:nil];
        }else {
            [self showAlertText:@"账号或密码错误"];
        }
    }];
}

- (void)showAlertText:(NSString *)text {
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"" message:text preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *cancle = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        
    }];
    [alert addAction:cancle];
    
    [self presentViewController:alert animated:YES completion:nil];
}
- (IBAction)privacyPolicy:(id)sender {

    NSURL *pathURL = [NSURL URLWithString:@"http://privacy.tticar.com/tticar/common.html"];
    
    YYSimpleWebViewController *webVC = [[YYSimpleWebViewController alloc] initWithURL:pathURL];
    [self.navigationController pushViewController:webVC animated:YES];
    
}

@end
